<?php 
set_time_limit(0);
ini_set("memory_limit", "12M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
//sort Date
function CompareDateASC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] < $b[0]) ? -1 : 1;
}
function CompareDateDESC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] > $b[0]) ? -1 : 1;
}
// sort UserID
function CompareUserIDASC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] < $b[1]) ? -1 : 1;
}
function CompareUserIDDESC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] > $b[1]) ? -1 : 1;
}
// sort DateStart
function CompareDateStartASC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] < $b[2]) ? -1 : 1;
}
function CompareDateStartDESC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] > $b[2]) ? -1 : 1;
}
//sort DateEnd
function CompareDateEndASC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] < $b[3]) ? -1 : 1;
}
function CompareDateEndDESC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] > $b[3]) ? -1 : 1;
}
//sort CarType
function CompareCarTypeASC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] < $b[4]) ? -1 : 1;
}
function CompareCarTypeDESC($a, $b){
	if ($a[4] == $b[4]) {
		return 0;
	}
	return ($a[4] > $b[4]) ? -1 : 1;
}
//sort Carnum
function CompareCarnumASC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] < $b[5]) ? -1 : 1;
}
function CompareCarnumDESC($a, $b){
	if ($a[5] == $b[5]) {
		return 0;
	}
	return ($a[5] > $b[5]) ? -1 : 1;
}
//sort IsReg
function CompareIsRegASC($a, $b){
	if ($a[6] == $b[6]) {
		return 0;
	}
	return ($a[6] < $b[6]) ? -1 : 1;
}
function CompareIsRegDESC($a, $b){
	if ($a[6] == $b[6]) {
		return 0;
	}
	return ($a[6] > $b[6]) ? -1 : 1;
}
if (isset($_SESSION['s_searchs']) and is_array($_SESSION['s_searchs']) and isset($_REQUEST['flag'])) {
	
	$mylist = $_SESSION['s_searchs'];
    if($_REQUEST['flag']=='10'){
		usort($mylist, 'CompareDateASC');
	}elseif($_REQUEST['flag']=='11'){
		usort($mylist, 'CompareDateDESC');
	}
	elseif($_REQUEST['flag']=='20'){
		usort($mylist, 'CompareUserIDASC');
	}elseif($_REQUEST['flag']=='21'){
		usort($mylist, 'CompareUserIDDESC');
	}
	elseif($_REQUEST['flag']=='30'){
		usort($mylist, 'CompareDateStartASC');
	}elseif($_REQUEST['flag']=='31'){
		usort($mylist, 'CompareDateStartDESC');
	}
	elseif($_REQUEST['flag']=='40'){
		usort($mylist, 'CompareDateEndASC');
	}elseif($_REQUEST['flag']=='41'){
		usort($mylist, 'CompareDateEndDESC');
	}	
	elseif($_REQUEST['flag']=='50'){
		usort($mylist, 'CompareCarTypeASC');
	}elseif($_REQUEST['flag']=='51'){
		usort($mylist, 'CompareCarTypeDESC');
	}	
	elseif($_REQUEST['flag']=='60'){
		usort($mylist, 'CompareCarnumASC');
	}elseif($_REQUEST['flag']=='61'){
		usort($mylist, 'CompareCarnumDESC');
	}	
	elseif($_REQUEST['flag']=='70'){
		usort($mylist, 'CompareIsRegASC');
	}elseif($_REQUEST['flag']=='71'){
		usort($mylist, 'CompareIsRegDESC');
	}	
	
	$_SESSION['s_searchs'] = $mylist;
	
	
	$real = 0;
	foreach ($mylist as $key =>$row){
		
		$real++;
	?>
		 <tr>
		 	<td width="14%"><?=$row[0]?></td>
		 	<td width="14%"><?=$row[1]?></td>
		 	<td width="14%"><?=$row[2]?></td>
		 	<td width="14%"><?=$row[3]?></td>
		 	<td width="14%"><?=$row[4]?>&nbsp;</td>
		 	<td width="14%"><?=$row[5]?>&nbsp;</td>
		 	<td  class="last"><?=$row[6]?></td>
		 </tr> 
						 
<?php  
	}
	if ($real>0 and $real<18) {
	 	foreach(range(0,18-$real) as $i){
	 		?>
	 		<tr>
		 	<td width="14%">&nbsp;</td>
		 	<td width="14%">&nbsp;</td>
		 	<td width="14%">&nbsp;</td>
		 	<td width="14%">&nbsp;</td>
		 	<td width="14%">&nbsp;</td>
		 	<td width="14%">&nbsp;</td>
		 	<td  class="last">&nbsp;</td>
		 	</tr>
	 	<?php }
	}
	
}
?>  